<?php
class ModulesController extends Custom_Controller_SpaceController
{

	public function init()
	{
		//初始化父类
		parent::init();
		$auth = Zend_Auth::getInstance();
		if (!$auth->hasIdentity()) {
			echo '对不起!请您登陆!';
		}
	}
	
	
	/**
	 * 模块首页
	 */
	public  function indexAction()
    {
    	
    }
    
    
    /**
     * 取到其中一个模块
     */
    public function getAction()
    {
    	$code = $this->_request->getParam('code');
    	$code = trim($code);
    	if(!preg_match('/[a-zA-Z0-9]/i',$code))return '';
    	$this->_helper->layout->disableLayout();
    	$this->_helper->viewRenderer->setNoRender(true);
    	$help = $this->view->getHelper('GetModule');    	
    	echo $help->getModule($code);
    }
    
    /**
     * 保存公司名字
     */
    public function nameAction()
    {
    	
    }

    
    /**
     * 保存改更的模块
     */
    public function saveAction()
    {
    	$parms = $this->_request->getParams();  
    	
    	//保存菜单 新版
		$menus = array();
		$umenu_listorder = $parms['umenu_listorder'];
		$umenu_name = $parms['umenu_name'];
		$umenu_isshow = $parms['umenu_isshow'];
		$existsMenu = array_keys($umenu_isshow);
		asort($umenu_listorder);			
		foreach ($umenu_listorder as $k=>$v){
			if(in_array($k,$existsMenu)){
				$menus[] = array(
					'name'=>$umenu_name[$k],
					'link'=>$k,
					'code'=>$k,
					'order' => $v,
				);
			}
		}
		//$menus = array();
		
    	//保存空间设置信息    	
    	//模块
    	$modules=array();
    	parse_str($parms['layoutinfo'],$modules);
    	
    	if(!is_array($modules['leftmod']))$modules['leftmod'] = array();
    	if(!is_array($modules['rightmod']))$modules['rightmod'] = array();
    	if(!is_array($modules['centermod']))$modules['centermod'] = array();
    	$spacesetting = array(
    		'bannerurl' => $parms['bannerurl'],
    		'skin' => $parms['skinid'],
    		'style' => $parms['styleid'],
    		'frame' => $parms['frameid'],
    		'contentclass' => $parms['contentclass'],
    		'blogname' => $parms['blogname'],
    		'template' => $parms['templateid'],
    		'bannerurl' => $parms['bannerurl'],
			'css' => array('logoCss'=>$parms['logoCss'],
					'companyNameCss'=>$parms['companyNameCss'],
					'sloganCss'=>$parms['sloganCss'],
					'searchCss'=>$parms['searchCss'],
					),
    		'left' => $modules['leftmod'],
    		'right' => $modules['rightmod'],
    		'center' => $modules['centermod'],
    		'modules' => array_merge(array_values($modules['leftmod']) , array_values($modules['rightmod']) , array_values($modules['centermod'])),
    		'menus' => $menus,
    	);
    	
    	$spacesetting = serialize($spacesetting);
    	$member=new Member();
    	$member->update(array('spaceconfig'=>$spacesetting),"uid=".$this->authUid);
    	setcookie('_dushijia_edit_style','',-time(),'/');	
    	$this->_redirect($this->view->urls('index','index','default',array('uid'=>$this->authUid),'companyroute'));
		exit();
    }

    
    /**
     * 退出模块编辑
     */
    public function exitAction()
    {
    	setcookie('_dushijia_edit_style','',-time(),'/');
    	exit();
    }

    
    /**
     * 编辑模块
     */
    public function editAction()
    {
    	setcookie('_dushijia_edit_style','1', time()+86300,'/');
    	
		$this->_redirect($this->view->urls('index','index','default',array('uid'=>$this->authUid),'companyroute'));
    }
    
    
    /**
     * 上传新的Banner
     */
    public function uploadAction()
    {
    	
    }
    
}